<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <canvas id="c1" width="600" height="400"></canvas>

    <script>
        /** @type {HTMLCanvasElement} */
        // 画布
        let c1 = document.getElementById("c1")
        // 画笔
        let ctx = c1.getContext("2d")
        // 绘制矩形 xy坐标+宽高
        ctx.fillRect(0, 0, 100, 100)
        // 绘制矩形框
        ctx.strokeRect(100, 100, 200, 100)
        // 逐渐清除画布
        let height = 0
        let timer = setInterval(() => {
            ctx.clearRect(0, 0, c1.clientWidth, height)
            height++ 
            if (height > c1.clientHeight) {
                clearInterval(timer)
            }
        }, 10)
        
    </script>
</body>

</html>